//
//  DZVisitorViewController.swift
//  Swift微博
//
//  Created by 董筱泽 on 16/10/23.
//  Copyright © 2016年 董筱泽. All rights reserved.
//

import UIKit

class DZVisitorViewController: UIViewController {

    var isLogin: Bool = DZUserAccountViewModel.sharedTools.isLogin
    // 访客视图
    var visitorView: DZVisitorView?
    
    override func loadView() {
        // 登录了
        if isLogin {
            super.loadView()
        }else {
            // 代表没有登录
            setupVisitorView()
            
        }
    }
    // MARK: - 设置访客视图
    private func  setupVisitorView(){
        // 创建访客视图
        visitorView = DZVisitorView()
        visitorView?.closure = {[weak self] in
            // 04- 闭包的回调
            self?.loginClick()
        }

        view = visitorView
        setupNav()
    }

    private func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(setHighlightedImgName: nil, title: "注册", target: self, action: #selector(loginClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(setHighlightedImgName: nil, title: "登录", target: self, action: #selector(loginClick))
    }
    
    @objc private func loginClick(){
               // 未来弹出微博登录控制器
        print("访客视图四个按钮点击")
        let oauthVc = HMOAuthViewController()
        let oauthNavC = DZNavigationController(rootViewController: oauthVc)
        present(oauthNavC, animated: true, completion:  nil)

    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
}
